package ar.com.ford.it.fullEconomics.interfaces;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Test {
    public static void main(String[] args) {
        try {
            //read file and store binary in bout
            ByteArrayOutputStream bout = new ByteArrayOutputStream();
            InputStream in = Test.class.getResourceAsStream("C:\\temp\\argparts.txt");
            int limite = 164;
            byte buffer[] = new byte[limite];
            
            int read = 0;
            do {
                read = in.read(buffer);
                if(read != -1) {
                    bout.write(buffer, 0, read);
                }
            } while(read != -1);
            
            //copy binary to an input stream for reading and parsing
            //save this for multiple uses
            ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
            BufferedReader bufRead = new BufferedReader(new InputStreamReader(bin));
            
            String line = "";
            
            do {
                line = bufRead.readLine();
                //parse ascii part here
                if(line != null) {
                    System.out.println(line);
                }
            } while(line != null);
            
            //now that you read the ascii part decide what you need to do.
            //to read binary, just do reads from bin directly
        }
        catch(Exception e) {
            e.printStackTrace();
        }
    }
    
}
